from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel, QPushButton
from PyQt5.QtCore import Qt
from TransferTools.Filer import get_local_ip

class MainWindow(QWidget):
    def __init__(self, controller):
        super(MainWindow, self).__init__()

        self.controller = controller
        self.config()
        self.container = QVBoxLayout()
        self.ip_label = QLabel()
        self.send_button = QPushButton("发送文件")
        self.receive_button = QPushButton("接收文件")

        self.equip_view()
        self.function_init()

    def config(self):
        self.controller.resize(720, 1080)
        self.controller.setWindowTitle("大文件传输助手")

    def equip_view(self):
        self.setLayout(self.container)

        # 层级关系
        self.container.addStretch(1)

        self.container.addWidget(self.ip_label)
        self.container.addWidget(self.send_button)
        self.container.addWidget(self.receive_button)

        self.container.addStretch(1)

        # 显示风格
        self.ip_label.setAlignment(Qt.AlignCenter)

    def function_init(self):
        ip = f"您的ip地址为：{get_local_ip()}"
        self.ip_label.setText(ip)

        # 绑定按钮时间槽
        self.send_button.clicked.connect(self.send_button_func)
        self.receive_button.clicked.connect(self.receive_button_func)

    def send_button_func(self):
        self.controller.change_view(1)

    def receive_button_func(self):
        self.controller.change_view(2)
